package src.dataStructures;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public abstract class Data implements Serializable {
	
	// These are the system controlled variables
	public int id;
	public String name;
	public int permission;
	public DetailLevel detail = DetailLevel.EMPTY;
	
	// These variables are free to edit
	public String description;
	public List<String> messages = new ArrayList<String>();

	/**
	 * This method returns a new data object with a defined amount of the current
	 * object copied into it
	 * @param detail The parameter that defines the amount to copy
	 * @return The new data object
	 */
	public Data copy(DetailLevel detail) {
		Data data;
		if (this instanceof User) data = new User();
		else data = new Item();
		data.detail = detail;
		return copyFull(data);
	}
	
	/**
	 * This method copies everything into the new object
	 * @param data The data to copy into
	 * @return The same data
	 */
	public Data copyFull(Data data) {
		data.id = id;
		data.name = name;
		data.permission = permission;
		return copy(data);
	}
	
	/**
	 * This method returns the current data object with a defined amount of the current
	 * object copied into it.  Uses the detail qualifier in the data object
	 * @param data The object to copy into
	 * @return The data object
	 */
	public Data copy(Data data) {
		switch (data.detail) {
		case FULL:
		case PUBLIC:
			data.messages = new ArrayList<String>();
			if (messages != null)
				messages.addAll(this.messages);
			data.description = description;
		case BRIEF:
		case EFFICIENT:
		case EMPTY:
		default:
		}
		return data;
	}
	
}
